﻿using System;
using System.Collections;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Reflection;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;

namespace HalconDotNet
{
    /// <summary>
    /// Interaction logic for HSmartWindowControlWPF.xaml
    /// </summary>
    // Token: 0x02000018 RID: 24
    [ToolboxBitmap(typeof(HSmartWindowControlWPF), "HWindowControlWPF.icon.bmp")]
    public class HSmartWindowControlWPF : ItemsControl, INotifyPropertyChanged, IDisposable
    {
        // Token: 0x17000037 RID: 55
        // (get) Token: 0x06000110 RID: 272 RVA: 0x000062B7 File Offset: 0x000044B7
        public HWindow HalconWindow
        {
            get
            {
                if (this._delayed)
                {
                    this.HInitializeWindow();
                }
                return this._hwindow;
            }
        }

        // Token: 0x17000038 RID: 56
        // (get) Token: 0x06000111 RID: 273 RVA: 0x000062CD File Offset: 0x000044CD
        public IntPtr HalconID
        {
            get
            {
                if (this._delayed)
                {
                    this.HInitializeWindow();
                }
                if (this._hwindow != null)
                {
                    return this._hwindow.Handle;
                }
                return HHandleBase.UNDEF;
            }
        }

        /// <summary>
        ///   Occurs after the HALCON window has been initialized
        /// </summary>
        // Token: 0x14000015 RID: 21
        // (add) Token: 0x06000112 RID: 274 RVA: 0x000062F8 File Offset: 0x000044F8
        // (remove) Token: 0x06000113 RID: 275 RVA: 0x00006330 File Offset: 0x00004530
        [Description("Occurs after the HALCON window has been initialized.")]
        [Category("Behavior")]
        public event HInitWindowEventHandler HInitWindow;

        // Token: 0x06000114 RID: 276 RVA: 0x00006365 File Offset: 0x00004565
        protected virtual void OnHInitWindow()
        {
            if (this.HInitWindow != null)
            {
                this.HInitWindow(this, new EventArgs());
            }
        }

        // Token: 0x17000039 RID: 57
        // (get) Token: 0x06000115 RID: 277 RVA: 0x00006380 File Offset: 0x00004580
        // (set) Token: 0x06000116 RID: 278 RVA: 0x00006392 File Offset: 0x00004592
        [Category("Behavior")]
        [EditorBrowsable(EditorBrowsableState.Always)]
        [Description("If on, the content of the HSmartWindowControlWPF is moved when the mouse pointer is dragged.")]
        public bool HMoveContent
        {
            get
            {
                return (bool)base.GetValue(HSmartWindowControlWPF.HMoveContentProperty);
            }
            set
            {
                base.SetValue(HSmartWindowControlWPF.HMoveContentProperty, value);
            }
        }

        // Token: 0x1700003A RID: 58
        // (get) Token: 0x06000117 RID: 279 RVA: 0x000063A5 File Offset: 0x000045A5
        // (set) Token: 0x06000118 RID: 280 RVA: 0x000063B7 File Offset: 0x000045B7
        [Category("Behavior")]
        [EditorBrowsable(EditorBrowsableState.Always)]
        [Description("Controls the behavior of the mouse wheel.")]
        public HSmartWindowControlWPF.ZoomContent HZoomContent
        {
            get
            {
                return (HSmartWindowControlWPF.ZoomContent)base.GetValue(HSmartWindowControlWPF.HZoomContentProperty);
            }
            set
            {
                base.SetValue(HSmartWindowControlWPF.HZoomContentProperty, value);
            }
        }

        /// <summary>
        /// Controls the value of the zoom factor set inside the property window
        /// </summary>
        // Token: 0x06000119 RID: 281 RVA: 0x000063CA File Offset: 0x000045CA
        private static bool HZoomFactorValidation(object value)
        {
            return (double)value > 1.0 && (double)value <= 100.0;
        }

        // Token: 0x1700003B RID: 59
        // (get) Token: 0x0600011A RID: 282 RVA: 0x000063F3 File Offset: 0x000045F3
        // (set) Token: 0x0600011B RID: 283 RVA: 0x00006405 File Offset: 0x00004605
        [Category("Behavior")]
        [EditorBrowsable(EditorBrowsableState.Always)]
        [Description("Controls the behavior of the zoom factor controlled by the mouse wheel.")]
        public double HZoomFactor
        {
            get
            {
                return (double)base.GetValue(HSmartWindowControlWPF.HZoomFactorProperty);
            }
            set
            {
                if (value > 1.0 && value <= 100.0)
                {
                    base.SetValue(HSmartWindowControlWPF.HZoomFactorProperty, value);
                }
            }
        }

        /// <summary>
        /// Default color for displaying HObjects. Unsets HColored property when set.
        /// </summary>
        // Token: 0x1700003C RID: 60
        // (get) Token: 0x0600011C RID: 284 RVA: 0x00006430 File Offset: 0x00004630
        // (set) Token: 0x0600011D RID: 285 RVA: 0x00006442 File Offset: 0x00004642
        [Category("Appearance")]
        [EditorBrowsable(EditorBrowsableState.Always)]
        [Description("Default color for displaying HRegion and HXLDCont objects. If HColor is set, HColored is set to null.")]
        public string HColor
        {
            get
            {
                return (string)base.GetValue(HSmartWindowControlWPF.HColorProperty);
            }
            set
            {
                base.SetValue(HSmartWindowControlWPF.HColorProperty, value);
            }
        }

        /// <summary>
        /// Default set of colors for displaying HObjects. Unsets the HColor property when set.
        /// </summary>
        // Token: 0x1700003D RID: 61
        // (get) Token: 0x0600011E RID: 286 RVA: 0x00006450 File Offset: 0x00004650
        // (set) Token: 0x0600011F RID: 287 RVA: 0x00006462 File Offset: 0x00004662
        [Category("Appearance")]
        [EditorBrowsable(EditorBrowsableState.Always)]
        [Description("Default set of colors for displaying HRegion and HXLDCont objects. If HColored is set, HColor is set to null.")]
        public int? HColored
        {
            get
            {
                return (int?)base.GetValue(HSmartWindowControlWPF.HColoredProperty);
            }
            set
            {
                base.SetValue(HSmartWindowControlWPF.HColoredProperty, value);
            }
        }

        /// <summary>
        /// Controls the line style of the margin of HRegion objects and of
        /// HXLDCont objects.
        /// </summary>
        // Token: 0x1700003E RID: 62
        // (get) Token: 0x06000120 RID: 288 RVA: 0x00006475 File Offset: 0x00004675
        // (set) Token: 0x06000121 RID: 289 RVA: 0x00006487 File Offset: 0x00004687
        [Category("Appearance")]
        [EditorBrowsable(EditorBrowsableState.Always)]
        [Description("Default output pattern of the margin of HRegion objects and of HXLDCont objects.")]
        public HLineStyleWPF HLineStyle
        {
            get
            {
                return (HLineStyleWPF)base.GetValue(HSmartWindowControlWPF.HLineStyleProperty);
            }
            set
            {
                base.SetValue(HSmartWindowControlWPF.HLineStyleProperty, value);
            }
        }

        /// <summary>
        /// Controls the default line width of HRegion and HXLDCont objects.
        /// </summary>
        // Token: 0x1700003F RID: 63
        // (get) Token: 0x06000122 RID: 290 RVA: 0x00006495 File Offset: 0x00004695
        // (set) Token: 0x06000123 RID: 291 RVA: 0x000064A7 File Offset: 0x000046A7
        [Category("Appearance")]
        [EditorBrowsable(EditorBrowsableState.Always)]
        [Description("Default line width of the margin of HRegion objects and of HXLDCont objects.")]
        public double? HLineWidth
        {
            get
            {
                return (double?)base.GetValue(HSmartWindowControlWPF.HLineWidthProperty);
            }
            set
            {
                base.SetValue(HSmartWindowControlWPF.HLineWidthProperty, value);
            }
        }

        /// <summary>
        /// Defines the default fill mode when HRegion objects are drawn.
        /// Can either be 'margin' or 'fill'.
        /// </summary>
        // Token: 0x17000040 RID: 64
        // (get) Token: 0x06000124 RID: 292 RVA: 0x000064BA File Offset: 0x000046BA
        // (set) Token: 0x06000125 RID: 293 RVA: 0x000064CC File Offset: 0x000046CC
        [Category("Appearance")]
        [EditorBrowsable(EditorBrowsableState.Always)]
        [Description("Default fill mode of HRegion objects.")]
        public string HDraw
        {
            get
            {
                return (string)base.GetValue(HSmartWindowControlWPF.HDrawProperty);
            }
            set
            {
                base.SetValue(HSmartWindowControlWPF.HDrawProperty, value);
            }
        }

        /// <summary>
        /// Sets the default Font for text displayed in the HSmartWindowControlWPF.
        /// </summary>
        // Token: 0x17000041 RID: 65
        // (get) Token: 0x06000126 RID: 294 RVA: 0x000064DA File Offset: 0x000046DA
        // (set) Token: 0x06000127 RID: 295 RVA: 0x000064EC File Offset: 0x000046EC
        [Category("Appearance")]
        [EditorBrowsable(EditorBrowsableState.Always)]
        [Description("Font for displaying messages in the HSmartWindowControlWPF.")]
        public string HFont
        {
            get
            {
                return (string)base.GetValue(HSmartWindowControlWPF.HFontProperty);
            }
            set
            {
                base.SetValue(HSmartWindowControlWPF.HFontProperty, value);
            }
        }

        /// <summary>
        /// Controls if the ImagePart is automatically set to the full image when
        /// a new image is dispayed.
        /// </summary>
        // Token: 0x17000042 RID: 66
        // (get) Token: 0x06000128 RID: 296 RVA: 0x000064FA File Offset: 0x000046FA
        // (set) Token: 0x06000129 RID: 297 RVA: 0x0000650C File Offset: 0x0000470C
        [Category("Behavior")]
        [EditorBrowsable(EditorBrowsableState.Always)]
        [Description("Disable that images are automatically scaled when they are displayed.")]
        public bool HDisableAutoResize
        {
            get
            {
                return (bool)base.GetValue(HSmartWindowControlWPF.HDisableAutoResizeProperty);
            }
            set
            {
                base.SetValue(HSmartWindowControlWPF.HDisableAutoResizeProperty, value);
            }
        }

        // Token: 0x0600012A RID: 298 RVA: 0x00006520 File Offset: 0x00004720
        private static void OnDrawingPropertyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            HSmartWindowControlWPF hsmartWindowControlWPF = sender as HSmartWindowControlWPF;
            if (hsmartWindowControlWPF == null)
            {
                return;
            }
            if (hsmartWindowControlWPF._hwindow != null)
            {
                string name = e.Property.Name;
                if (!(name == "HLineStyle"))
                {
                    if (!(name == "HLineWidth"))
                    {
                        if (!(name == "HDraw"))
                        {
                            if (!(name == "HColored"))
                            {
                                if (!(name == "HColor"))
                                {
                                    if (name == "HFont")
                                    {
                                        hsmartWindowControlWPF._hwindow.SetFont((string)e.NewValue);
                                    }
                                }
                                else
                                {
                                    hsmartWindowControlWPF.HColored = null;
                                    hsmartWindowControlWPF._hwindow.SetColor((string)e.NewValue);
                                }
                            }
                            else
                            {
                                hsmartWindowControlWPF.HColor = null;
                                hsmartWindowControlWPF._hwindow.SetColored(((int?)e.NewValue) ?? 0);
                            }
                        }
                        else
                        {
                            hsmartWindowControlWPF._hwindow.SetDraw((string)e.NewValue);
                        }
                    }
                    else
                    {
                        hsmartWindowControlWPF._hwindow.SetLineWidth(((double?)e.NewValue) ?? 1.0);
                    }
                }
                else
                {
                    hsmartWindowControlWPF._hwindow.SetLineStyle((HLineStyleWPF)e.NewValue);
                }
                hsmartWindowControlWPF.OnItemsChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
            }
        }

        // Token: 0x17000043 RID: 67
        // (get) Token: 0x0600012B RID: 299 RVA: 0x000066A0 File Offset: 0x000048A0
        // (set) Token: 0x0600012C RID: 300 RVA: 0x000066B2 File Offset: 0x000048B2
        [Category("Miscellaneous")]
        [EditorBrowsable(EditorBrowsableState.Never)]
        [Description("Displays the assigned HImage or HObject.")]
        [Obsolete("This property has been depcrecated. Please us the Items property instead.")]
        public HObject HDisplayCurrentObject
        {
            get
            {
                return (HObject)base.GetValue(HSmartWindowControlWPF.HDisplayCurrentObjectProperty);
            }
            set
            {
                base.SetValue(HSmartWindowControlWPF.HDisplayCurrentObjectProperty, value);
            }
        }

        // Token: 0x0600012D RID: 301 RVA: 0x000066C0 File Offset: 0x000048C0
        private static void OnDisplayObjectChanged(DependencyObject source, DependencyPropertyChangedEventArgs e)
        {
            HSmartWindowControlWPF hsmartWindowControlWPF = source as HSmartWindowControlWPF;
            HObject newItem = (HObject)e.NewValue;
            hsmartWindowControlWPF.Items.Clear();
            hsmartWindowControlWPF.Items.Add(newItem);
        }

        // Token: 0x0600012E RID: 302 RVA: 0x000066F7 File Offset: 0x000048F7
        internal void NotifyItemsChanged()
        {
            this.OnItemsChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
        }

        // Token: 0x0600012F RID: 303 RVA: 0x00006708 File Offset: 0x00004908
        protected override void OnItemsChanged(NotifyCollectionChangedEventArgs e)
        {
            if (this._hwindow == null)
            {
                return;
            }
            if (e.Action == NotifyCollectionChangedAction.Add)
            {
                foreach (object obj in e.NewItems)
                {
                    if (obj.GetType().IsSubclassOf(typeof(HObject)) || obj.GetType() == typeof(HObject))
                    {
                        ((HObject)obj).DispObj(this._hwindow);
                    }
                    else if (obj.GetType().IsSubclassOf(typeof(HDisplayObjectWPF)))
                    {
                        ((HDisplayObjectWPF)obj).Display(this._hwindow);
                        if (this.HColor != null)
                        {
                            this._hwindow.SetColor(this.HColor);
                        }
                        if (this.HColored != null)
                        {
                            this._hwindow.SetColored(this.HColored ?? 0);
                        }
                    }
                }
                if (!this.HDisableAutoResize)
                {
                    this.SetFullImagePart(null);
                    return;
                }
            }
            else
            {
                this._hwindow.ClearWindow();
                foreach (object obj2 in ((IEnumerable)base.Items))
                {
                    if (obj2.GetType().IsSubclassOf(typeof(HObject)) || obj2.GetType() == typeof(HObject))
                    {
                        ((HObject)obj2).DispObj(this._hwindow);
                        if (this.HColor != null)
                        {
                            this._hwindow.SetColor(this.HColor);
                        }
                        if (this.HColored != null)
                        {
                            this._hwindow.SetColored(this.HColored ?? 0);
                        }
                    }
                    else if (obj2.GetType().IsSubclassOf(typeof(HDisplayObjectWPF)))
                    {
                        ((HDisplayObjectWPF)obj2).Display(this._hwindow);
                        if (this.HColor != null)
                        {
                            this._hwindow.SetColor(this.HColor);
                        }
                        if (this.HColored != null)
                        {
                            this._hwindow.SetColored(this.HColored ?? 0);
                        }
                    }
                }
                if (!this.HDisableAutoResize)
                {
                    this.SetFullImagePart(null);
                }
            }
        }

        // Token: 0x17000044 RID: 68
        // (get) Token: 0x06000130 RID: 304 RVA: 0x000069BC File Offset: 0x00004BBC
        // (set) Token: 0x06000131 RID: 305 RVA: 0x000069CE File Offset: 0x00004BCE
        [Category("Behavior")]
        [EditorBrowsable(EditorBrowsableState.Always)]
        [Description("Modifier key to interact with drawing objects. If a modifier key is selected, the user can only interact with drawing objects while keeping the modifier key pressed. This is especially useful when interacting with XLD drawing objects.")]
        public HSmartWindowControlWPF.DrawingObjectsModifier HDrawingObjectsModifier
        {
            get
            {
                return (HSmartWindowControlWPF.DrawingObjectsModifier)base.GetValue(HSmartWindowControlWPF.HDrawingObjectsModifierProperty);
            }
            set
            {
                base.SetValue(HSmartWindowControlWPF.HDrawingObjectsModifierProperty, value);
            }
        }

        // Token: 0x17000045 RID: 69
        // (get) Token: 0x06000132 RID: 306 RVA: 0x000069E1 File Offset: 0x00004BE1
        // (set) Token: 0x06000133 RID: 307 RVA: 0x000069F3 File Offset: 0x00004BF3
        [Category("Behavior")]
        [EditorBrowsable(EditorBrowsableState.Always)]
        [Description("If on, the content of the HSmartWindowControlWPF keeps its aspect ratio when the control is resized or zoomed.")]
        public bool HKeepAspectRatio
        {
            get
            {
                return (bool)base.GetValue(HSmartWindowControlWPF.HKeepAspectRatioProperty);
            }
            set
            {
                base.SetValue(HSmartWindowControlWPF.HKeepAspectRatioProperty, value);
            }
        }

        // Token: 0x17000046 RID: 70
        // (get) Token: 0x06000134 RID: 308 RVA: 0x00006A06 File Offset: 0x00004C06
        // (set) Token: 0x06000135 RID: 309 RVA: 0x00006A18 File Offset: 0x00004C18
        [Category("Behavior")]
        [EditorBrowsable(EditorBrowsableState.Always)]
        [Description("If on, double clicking resizes the content of the HSmartWindowControlWPF to fit the size of the control.")]
        public bool HDoubleClickToFitContent
        {
            get
            {
                return (bool)base.GetValue(HSmartWindowControlWPF.HDoubleClickToFitContentProperty);
            }
            set
            {
                base.SetValue(HSmartWindowControlWPF.HDoubleClickToFitContentProperty, value);
            }
        }

        // Token: 0x06000136 RID: 310 RVA: 0x00006A2C File Offset: 0x00004C2C
        private static void OnHImagePartChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            HSmartWindowControlWPF hsmartWindowControlWPF = sender as HSmartWindowControlWPF;
            if (hsmartWindowControlWPF._hwindow != null)
            {
                Rect rect = (Rect)e.NewValue;
                hsmartWindowControlWPF._hwindow.SetPart(rect.Top, rect.Left, rect.Bottom - 1.0, rect.Right - 1.0);
            }
        }

        // Token: 0x17000047 RID: 71
        // (get) Token: 0x06000137 RID: 311 RVA: 0x00006AA4 File Offset: 0x00004CA4
        // (set) Token: 0x06000138 RID: 312 RVA: 0x00006B32 File Offset: 0x00004D32
        [Category("Layout")]
        [EditorBrowsable(EditorBrowsableState.Always)]
        [Description("Visible image part (Column, Row, Width, Height).")]
        public Rect HImagePart
        {
            get
            {
                if (this._hwindow != null)
                {
                    double num;
                    double num2;
                    double num3;
                    double num4;
                    this.GetFloatPart(this._hwindow, out num, out num2, out num3, out num4);
                    Rect rect = default(Rect);
                    rect.X = num2;
                    rect.Y = num;
                    rect.Width = num4 - num2 + 1.0;
                    rect.Height = num3 - num + 1.0;
                    base.SetValue(HSmartWindowControlWPF.HImagePartProperty, rect);
                    return rect;
                }
                return (Rect)base.GetValue(HSmartWindowControlWPF.HImagePartProperty);
            }
            set
            {
                base.SetValue(HSmartWindowControlWPF.HImagePartProperty, value);
            }
        }

        /// <summary>
        /// Current size of the corresponding HALCON window.
        /// </summary>
        // Token: 0x17000048 RID: 72
        // (get) Token: 0x06000139 RID: 313 RVA: 0x00006B45 File Offset: 0x00004D45
        // (set) Token: 0x0600013A RID: 314 RVA: 0x00006B58 File Offset: 0x00004D58
        public System.Windows.Size WindowSize
        {
            get
            {
                return (System.Windows.Size)base.GetValue(HSmartWindowControlWPF.WindowSizeProperty);
            }
            set
            {
                if (value.Width <= 0.0 || value.Height <= 0.0)
                {
                    return;
                }
                if (!this._delayed)
                {
                    int num;
                    int num2;
                    int width;
                    int height;
                    this._hwindow.GetWindowExtents(out num, out num2, out width, out height);
                    try
                    {
                        this._hwindow.SetWindowExtents(0, 0, (int)this.WindowSize.Width, (int)this.WindowSize.Height);
                        base.SetValue(HSmartWindowControlWPF.WindowSizeProperty, value);
                    }
                    catch (HalconException)
                    {
                        this._hwindow.SetWindowExtents(0, 0, width, height);
                    }
                }
            }
        }

        /// <summary>
        ///   Occurs when a button is pressed over a HALCON window.
        ///   Note that delta is meaningless here.
        /// </summary>
        // Token: 0x14000016 RID: 22
        // (add) Token: 0x0600013B RID: 315 RVA: 0x00006C08 File Offset: 0x00004E08
        // (remove) Token: 0x0600013C RID: 316 RVA: 0x00006C40 File Offset: 0x00004E40
        public event HSmartWindowControlWPF.HMouseEventHandlerWPF HMouseDown;

        /// <summary>
        ///   Occurs when a button is released over a HALCON window.
        ///   Note that delta is meaningless here.
        /// </summary>
        // Token: 0x14000017 RID: 23
        // (add) Token: 0x0600013D RID: 317 RVA: 0x00006C78 File Offset: 0x00004E78
        // (remove) Token: 0x0600013E RID: 318 RVA: 0x00006CB0 File Offset: 0x00004EB0
        public event HSmartWindowControlWPF.HMouseEventHandlerWPF HMouseUp;

        /// <summary>
        ///   Occurs when the wheel is used over a HALCON window while it has
        ///   focus. Note that button is meaningless here.
        /// </summary>
        // Token: 0x14000018 RID: 24
        // (add) Token: 0x0600013F RID: 319 RVA: 0x00006CE8 File Offset: 0x00004EE8
        // (remove) Token: 0x06000140 RID: 320 RVA: 0x00006D20 File Offset: 0x00004F20
        public event HSmartWindowControlWPF.HMouseEventHandlerWPF HMouseWheel;

        /// <summary>
        ///   Occurs when the mouse is moved over a HALCON window.
        ///   Note that delta is meaningless here.
        /// </summary>
        // Token: 0x14000019 RID: 25
        // (add) Token: 0x06000141 RID: 321 RVA: 0x00006D58 File Offset: 0x00004F58
        // (remove) Token: 0x06000142 RID: 322 RVA: 0x00006D90 File Offset: 0x00004F90
        public event HSmartWindowControlWPF.HMouseEventHandlerWPF HMouseMove;

        /// <summary>
        ///   Occurs when a button is double-clicked over a HALCON window.
        ///   Note that delta is meaningless here.
        /// </summary>
        // Token: 0x1400001A RID: 26
        // (add) Token: 0x06000143 RID: 323 RVA: 0x00006DC8 File Offset: 0x00004FC8
        // (remove) Token: 0x06000144 RID: 324 RVA: 0x00006E00 File Offset: 0x00005000
        public event HSmartWindowControlWPF.HMouseEventHandlerWPF HMouseDoubleClick;

        /// <summary>
        /// Occurs when an internal error in the HSmartWindowControl WPF happens.
        /// </summary>
        // Token: 0x1400001B RID: 27
        // (add) Token: 0x06000145 RID: 325 RVA: 0x00006E38 File Offset: 0x00005038
        // (remove) Token: 0x06000146 RID: 326 RVA: 0x00006E70 File Offset: 0x00005070
        public event HSmartWindowControlWPF.HErrorHandler HErrorNotify;

        // Token: 0x06000147 RID: 327 RVA: 0x00006EA8 File Offset: 0x000050A8
        public HSmartWindowControlWPF()
        {
            base.Margin = new Thickness(0.0);
            base.MouseWheel += this.HWPFWindow_MouseWheel;
            base.MouseMove += this.HWPFWindow_MouseMove;
            base.MouseDown += this.HWPFWindow_MouseDown;
            base.MouseUp += this.HWPFWindow_MouseUp;
            base.MouseDoubleClick += this.HWPFWindow_MouseDoubleClick;
            base.MouseLeave += this.HWPFWindow_MouseLeave;
            base.ItemsPanel = null;
            this._window_frame = new Viewbox();
            this._window_frame.Stretch = Stretch.None;
            this._window_frame.MouseLeave += this.HWPFWindow_MouseLeave;
            this.HInitializeWindow();
        }

        // Token: 0x06000148 RID: 328 RVA: 0x00006F78 File Offset: 0x00005178
        private void HInitializeWindow()
        {
            this._delayed = (base.RenderSize.Width <= 0.0 || base.RenderSize.Height <= 0.0);
            if (this._delayed && base.Parent != null)
            {
                FrameworkElement frameworkElement = base.Parent as FrameworkElement;
                if (frameworkElement != null)
                {
                    base.RenderSize = frameworkElement.RenderSize;
                    this._delayed = (base.RenderSize.Width <= 0.0 || base.RenderSize.Height <= 0.0);
                }
            }
            if (!this._delayed)
            {
                System.Windows.Size renderSize = base.RenderSize;
                base.Dispatcher.ShutdownStarted += this.Dispatcher_ShutdownStarted;
                Rect himagePart = this.HImagePart;
                this._hwindow = new HWindow(0, 0, (int)renderSize.Width, (int)renderSize.Height, 0, "buffer", "");
                this._hwindow.SetWindowParam("graphics_stack", "true");
                if (this.HDraw != null)
                {
                    this._hwindow.SetDraw(this.HDraw);
                }
                if (this.HLineStyle != null)
                {
                    this._hwindow.SetLineStyle(this.HLineStyle);
                }
                if (this.HLineWidth != null)
                {
                    this._hwindow.SetLineWidth(this.HLineWidth ?? 1.0);
                }
                if (this.HColor != null)
                {
                    this._hwindow.SetColor(this.HColor);
                }
                if (this.HColored != null)
                {
                    this._hwindow.SetColored(this.HColored ?? 0);
                }
                if (this.HFont != null)
                {
                    this._hwindow.SetFont(this.HFont);
                }
                this._hwindow.SetPart(himagePart.Top, himagePart.Left, himagePart.Bottom - 1.0, himagePart.Right - 1.0);
                this._prevsize.Width = (int)base.ActualWidth;
                this._prevsize.Height = (int)base.ActualHeight;
                using (Graphics graphics = Graphics.FromHwnd(IntPtr.Zero))
                {
                    this._dpiX = (double)graphics.DpiX;
                    this._dpiY = (double)graphics.DpiY;
                }
                this._dump_params = new HTuple(this._hwindow);
                this._dump_params[1] = "interleaved";
                this._hwindow.OnContentUpdate(delegate (IntPtr content)
                {
                    base.Dispatcher.BeginInvoke(new Action(base.InvalidateVisual), new object[0]);
                    return 2;
                });
                if (this.HInitWindow != null)
                {
                    this.OnHInitWindow();
                }
            }
        }

        // Token: 0x06000149 RID: 329 RVA: 0x00007284 File Offset: 0x00005484
        private System.Drawing.Size AspectRatioSize(System.Drawing.Size imgsize)
        {
            return default(System.Drawing.Size);
        }

        /// <summary>
        /// Finish event handling before there is no WPF control to draw into.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        // Token: 0x0600014A RID: 330 RVA: 0x0000729A File Offset: 0x0000549A
        private void Dispatcher_ShutdownStarted(object sender, EventArgs e)
        {
            this.Dispose();
        }

        /// <summary>Releases the resources used by the native HALCON window</summary>
        // Token: 0x0600014B RID: 331 RVA: 0x000072A2 File Offset: 0x000054A2
        public void Dispose()
        {
            base.Dispatcher.ShutdownStarted -= this.Dispatcher_ShutdownStarted;
            if (this._hwindow != null)
            {
                this._hwindow.Dispose();
            }
            if (this._dump_params != null)
            {
                this._dump_params.Dispose();
            }
        }

        /// <summary>
        /// From https://blogs.msdn.microsoft.com/dwayneneed/2007/10/05/blurry-bitmaps/.
        /// Helper code to get the (subpixel) offset of the control
        /// </summary>
        /// <param name="v"></param>
        /// <returns></returns>
        // Token: 0x0600014C RID: 332 RVA: 0x000072E4 File Offset: 0x000054E4
        private Matrix GetVisualTransform(Visual v)
        {
            if (v != null)
            {
                Matrix matrix = Matrix.Identity;
                Transform transform = VisualTreeHelper.GetTransform(v);
                if (transform != null)
                {
                    Matrix value = transform.Value;
                    matrix = Matrix.Multiply(matrix, value);
                }
                Vector offset = VisualTreeHelper.GetOffset(v);
                matrix.Translate(offset.X, offset.Y);
                return matrix;
            }
            return Matrix.Identity;
        }

        /// <summary>
        /// From https://blogs.msdn.microsoft.com/dwayneneed/2007/10/05/blurry-bitmaps/.
        /// Helper code to get the (subpixel) offset of the control
        /// </summary>
        /// <param name="point"></param>
        /// <param name="v"></param>
        /// <param name="inverse"></param>
        /// <param name="throwOnError"></param>
        /// <param name="success"></param>
        /// <returns></returns>
        // Token: 0x0600014D RID: 333 RVA: 0x00007338 File Offset: 0x00005538
        private System.Windows.Point TryApplyVisualTransform(System.Windows.Point point, Visual v, bool inverse, bool throwOnError, out bool success)
        {
            success = true;
            if (v != null)
            {
                Matrix visualTransform = this.GetVisualTransform(v);
                if (inverse)
                {
                    if (!throwOnError && !visualTransform.HasInverse)
                    {
                        success = false;
                        return new System.Windows.Point(0.0, 0.0);
                    }
                    visualTransform.Invert();
                }
                point = visualTransform.Transform(point);
            }
            return point;
        }

        /// <summary>
        /// From https://blogs.msdn.microsoft.com/dwayneneed/2007/10/05/blurry-bitmaps/.
        /// Helper code to get the (subpixel) offset of the control
        /// </summary>
        /// <param name="point"></param>
        /// <param name="v"></param>
        /// <param name="inverse"></param>
        /// <returns></returns>
        // Token: 0x0600014E RID: 334 RVA: 0x00007394 File Offset: 0x00005594
        private System.Windows.Point ApplyVisualTransform(System.Windows.Point point, Visual v, bool inverse)
        {
            bool flag = true;
            return this.TryApplyVisualTransform(point, v, inverse, true, out flag);
        }

        /// <summary>
        /// From https://blogs.msdn.microsoft.com/dwayneneed/2007/10/05/blurry-bitmaps/.
        /// Helper code to get the (subpixel) offset of the control
        /// </summary>
        /// <returns></returns>
        // Token: 0x0600014F RID: 335 RVA: 0x000073B0 File Offset: 0x000055B0
        private System.Windows.Point GetPixelOffset()
        {
            System.Windows.Point point = default(System.Windows.Point);
            PresentationSource presentationSource = PresentationSource.FromVisual(this);
            if (presentationSource != null)
            {
                Visual rootVisual = presentationSource.RootVisual;
                if (((FrameworkElement)rootVisual).ActualHeight > 0.0 && ((FrameworkElement)rootVisual).ActualWidth > 0.0)
                {
                    point = base.TransformToAncestor(rootVisual).Transform(point);
                    point = this.ApplyVisualTransform(point, rootVisual, false);
                    point = presentationSource.CompositionTarget.TransformToDevice.Transform(point);
                    point.X = Math.Round(point.X);
                    point.Y = Math.Round(point.Y);
                    point = presentationSource.CompositionTarget.TransformFromDevice.Transform(point);
                    point = this.ApplyVisualTransform(point, rootVisual, true);
                    point = rootVisual.TransformToDescendant(this).Transform(point);
                }
            }
            return point;
        }

        /// <summary>
        /// Draw the contents of the smart buffer
        ///
        /// Instead of using an Image control to render the contents of the
        /// buffer window, the contents are directly rendered to the
        /// DrawingContext passed to OnRender()
        ///
        /// OnRender also handles resizing of the control. This way,
        /// set_window_extents is called far less then in the respective
        /// delegate.
        /// </summary>
        /// <param name="drawingContext"></param>
        // Token: 0x06000150 RID: 336 RVA: 0x0000748C File Offset: 0x0000568C
        protected override void OnRender(DrawingContext drawingContext)
        {
            bool flag = false;
            if (base.Background != null)
            {
                base.Background = null;
            }
            if (DesignerProperties.GetIsInDesignMode(this))
            {
                Stream manifestResourceStream = Assembly.GetExecutingAssembly().GetManifestResourceStream("HalconDotNet.halcon_icon_48.png");
                if (manifestResourceStream == null)
                {
                    drawingContext.DrawRectangle(new SolidColorBrush(Colors.Black), null, new Rect(0.0, 0.0, base.ActualWidth, base.ActualHeight));
                    return;
                }
                try
                {
                    BitmapImage bitmapImage = new BitmapImage();
                    bitmapImage.BeginInit();
                    bitmapImage.StreamSource = manifestResourceStream;
                    bitmapImage.EndInit();
                    int num = (int)base.ActualWidth / 2 - 24;
                    int num2 = (int)base.ActualHeight / 2 - 24;
                    drawingContext.DrawRectangle(new SolidColorBrush(Colors.Black), null, new Rect(0.0, 0.0, base.ActualWidth, base.ActualHeight));
                    if (base.ActualWidth > 48.0 && base.ActualHeight > 48.0)
                    {
                        drawingContext.DrawImage(bitmapImage, new Rect((double)num, (double)num2, 48.0, 48.0));
                    }
                }
                catch
                {
                }
                return;
            }
            else
            {
                if (this._hwindow == null || this._delayed)
                {
                    this.HInitializeWindow();
                }
                if (this._hwindow == null)
                {
                    base.Measure(new System.Windows.Size(double.PositiveInfinity, double.PositiveInfinity));
                    return;
                }
                if (base.ActualWidth < 1.0 || base.ActualHeight < 1.0)
                {
                    drawingContext.DrawRectangle(new SolidColorBrush(Colors.Black), null, new Rect(0.0, 0.0, base.ActualWidth, base.ActualHeight));
                    return;
                }
                int num3;
                int num4;
                int num5;
                int num6;
                this._hwindow.GetWindowExtents(out num3, out num4, out num5, out num6);
                if (num5 != (int)base.ActualWidth || num6 != (int)base.ActualHeight)
                {
                    this.WindowSize = new System.Windows.Size(base.ActualWidth, base.ActualHeight);
                    flag = true;
                }
                if (this.HKeepAspectRatio && flag)
                {
                    HTuple htuple = new HTuple(this._hwindow);
                    this.calculate_part(htuple, this._prevsize.Width, this._prevsize.Height);
                    htuple.Dispose();
                    this.SetFullImagePart(null);
                }
                this._prevsize.Width = (int)base.ActualWidth;
                this._prevsize.Height = (int)base.ActualHeight;
                if (this._dumpimg != null)
                {
                    this._dumpimg.Dispose();
                }
                HOperatorSet.DumpWindowImage(out this._dumpimg, this._dump_params);
                HTuple htuple2;
                HTuple htuple3;
                HTuple htuple4;
                HTuple htuple5;
                HOperatorSet.GetImagePointer1(this._dumpimg, out htuple2, out htuple3, out htuple4, out htuple5);
                IntPtr buffer = (IntPtr)htuple2.L;
                if (this._wbitmap == null || htuple4 / 4 != (int)this._wbitmap.Width || htuple5 != (int)this._wbitmap.Height)
                {
                    this._wbitmap = new WriteableBitmap(htuple4 / 4, htuple5, this._dpiX, this._dpiY, PixelFormats.Bgra32, null);
                }
                this._wbitmap.Lock();
                this._wbitmap.WritePixels(new Int32Rect(0, 0, htuple4 / 4, htuple5), buffer, htuple4 * htuple5, htuple4);
                this._wbitmap.Unlock();
                System.Windows.Point pixelOffset = this.GetPixelOffset();
                drawingContext.DrawImage(this._wbitmap, new Rect(pixelOffset.X, pixelOffset.Y, htuple4 / 4, htuple5));
                return;
            }
        }

        // Token: 0x06000151 RID: 337 RVA: 0x00007850 File Offset: 0x00005A50
        private HSmartWindowControlWPF.HMouseEventArgsWPF ToHMouse(int x, int y, MouseEventArgs e, int delta)
        {
            MouseButton? button = null;
            double row;
            double column;
            this._hwindow.ConvertCoordinatesWindowToImage((double)y, (double)x, out row, out column);
            if (e != null)
            {
                if (e.LeftButton == MouseButtonState.Pressed)
                {
                    button = new MouseButton?(MouseButton.Left);
                }
                else if (e.RightButton == MouseButtonState.Pressed)
                {
                    button = new MouseButton?(MouseButton.Right);
                }
                else if (e.MiddleButton == MouseButtonState.Pressed)
                {
                    button = new MouseButton?(MouseButton.Middle);
                }
                else if (e.XButton1 == MouseButtonState.Pressed)
                {
                    button = new MouseButton?(MouseButton.XButton1);
                }
                else if (e.XButton2 == MouseButtonState.Pressed)
                {
                    button = new MouseButton?(MouseButton.XButton2);
                }
            }
            return new HSmartWindowControlWPF.HMouseEventArgsWPF((double)x, (double)y, row, column, delta, button);
        }

        // Token: 0x06000152 RID: 338 RVA: 0x000078E8 File Offset: 0x00005AE8
        private void GetFloatPart(HWindow window, out double l1, out double c1, out double l2, out double c2)
        {
            HTuple t;
            HTuple t2;
            HTuple t3;
            HTuple t4;
            window.GetPart(out t, out t2, out t3, out t4);
            l1 = t;
            c1 = t2;
            l2 = t3;
            c2 = t4;
        }

        /// <summary>
        /// Zoom the contents of the HALCON window keeping the point (x, y) invariant.
        /// Please notice that the point is given in native coordinates (i.e. position of
        /// the mouse cursor relative to the upper left corner of the control).
        /// </summary>
        /// <param name="x">Column coordinate of the invariant point.</param>
        /// <param name="y">Row coordinate of the invariant point.</param>
        /// <param name="Delta">Scaling factor (multiple of 120).</param>
        // Token: 0x06000153 RID: 339 RVA: 0x00007928 File Offset: 0x00005B28
        public void HZoomWindowContents(double x, double y, int Delta)
        {
            HTuple homMat2D;
            HOperatorSet.HomMat2dIdentity(out homMat2D);
            double d;
            double d2;
            this.ConvertWindowsCoordinatesToHImage(y, x, out d, out d2);
            double num = (Delta < 0) ? this.HZoomFactor : (1.0 / this.HZoomFactor);
            if (this.HZoomContent == HSmartWindowControlWPF.ZoomContent.WheelBackwardZoomsIn)
            {
                num = 1.0 / num;
            }
            for (int i = Math.Abs(Delta) / 120; i > 1; i--)
            {
                num *= ((Delta < 0) ? this.HZoomFactor : (1.0 / this.HZoomFactor));
            }
            HTuple homMat2D2;
            HOperatorSet.HomMat2dScale(homMat2D, num, num, d2, d, out homMat2D2);
            double num2;
            double num3;
            double num4;
            double num5;
            this.GetFloatPart(this._hwindow, out num2, out num3, out num4, out num5);
            HTuple htuple;
            HTuple htuple2;
            HOperatorSet.AffineTransPoint2d(homMat2D2, num3, num2, out htuple, out htuple2);
            HTuple htuple3;
            HTuple htuple4;
            HOperatorSet.AffineTransPoint2d(homMat2D2, num5, num4, out htuple3, out htuple4);
            try
            {
                this.HImagePart = new Rect(htuple.D, htuple2.D, htuple3.D - htuple.D + 1.0, htuple4.D - htuple2.D + 1.0);
            }
            catch (Exception)
            {
                try
                {
                    this.HImagePart = new Rect(num3, num2, num5 - num3 + 1.0, num4 - num2 + 1.0);
                }
                catch (HalconException)
                {
                }
            }
        }

        /// <summary>
        /// Provide zooming out of the box.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        // Token: 0x06000154 RID: 340 RVA: 0x00007ABC File Offset: 0x00005CBC
        private void HWPFWindow_MouseWheel(object sender, MouseWheelEventArgs e)
        {
            HSmartWindowControlWPF.HMouseEventArgsWPF e2 = null;
            try
            {
                if (this.HZoomContent != HSmartWindowControlWPF.ZoomContent.Off)
                {
                    this._last_position = this.GetPosition(e);
                    this.HZoomWindowContents(this._last_position.X, this._last_position.Y, e.Delta);
                }
                e2 = this.ToHMouse((int)this._last_position.X, (int)this._last_position.Y, null, e.Delta);
            }
            catch (HalconException he)
            {
                if (this.HErrorNotify != null)
                {
                    this.HErrorNotify(he);
                }
            }
            if (this.HMouseWheel != null)
            {
                this.HMouseWheel(this, e2);
            }
        }

        /// <summary>
        /// Translates WPF mouse coordinates into HALCON image coordinates.
        /// </summary>
        /// <param name="wr"></param>
        /// <param name="wc"></param>
        /// <param name="ir"></param>
        /// <param name="ic"></param>
        // Token: 0x06000155 RID: 341 RVA: 0x00007B68 File Offset: 0x00005D68
        private void ConvertWindowsCoordinatesToHImage(double wr, double wc, out double ir, out double ic)
        {
            this._hwindow.ConvertCoordinatesWindowToImage(wr, wc, out ir, out ic);
        }

        /// <summary>
        /// Translates native encoding of mouse button state to HALCON encoding
        /// (see get_mposition).
        /// </summary>
        /// <param name="e"></param>
        /// <returns></returns>
        // Token: 0x06000156 RID: 342 RVA: 0x00007B7A File Offset: 0x00005D7A
        private int MouseEventToInt(MouseEventArgs e)
        {
            if (e.LeftButton == MouseButtonState.Pressed)
            {
                return 1;
            }
            if (e.RightButton == MouseButtonState.Pressed)
            {
                return 4;
            }
            if (e.MiddleButton == MouseButtonState.Pressed)
            {
                return 2;
            }
            return 0;
        }

        /// <summary>
        /// Translates native encoding of mouse button action to HALCON encoding
        /// (see get_mposition).
        /// </summary>
        /// <param name="e"></param>
        /// <returns></returns>
        // Token: 0x06000157 RID: 343 RVA: 0x00007B9E File Offset: 0x00005D9E
        private int MouseButtonEventToInt(MouseButtonEventArgs e)
        {
            if (e.ChangedButton == MouseButton.Left)
            {
                return 1;
            }
            if (e.ChangedButton == MouseButton.Right)
            {
                return 4;
            }
            if (e.ChangedButton == MouseButton.Middle)
            {
                return 2;
            }
            return 0;
        }

        /// <summary>
        /// Depending on the setting of HDrawingObjectsModifier, return true,
        /// if drawing object should be manipulated now.
        /// </summary>
        /// <returns>True if the user is currently pressing the left shift key.
        /// </returns>
        // Token: 0x06000158 RID: 344 RVA: 0x00007BC4 File Offset: 0x00005DC4
        private bool InteractingWithDrawingObjs()
        {
            switch (this.HDrawingObjectsModifier)
            {
                case HSmartWindowControlWPF.DrawingObjectsModifier.Shift:
                    return Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift);
                case HSmartWindowControlWPF.DrawingObjectsModifier.Ctrl:
                    return Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl);
                case HSmartWindowControlWPF.DrawingObjectsModifier.Alt:
                    return Keyboard.IsKeyDown(Key.LeftAlt) || Keyboard.IsKeyDown(Key.RightAlt);
                default:
                    return true;
            }
        }

        /// <summary>
        /// Shifts the window contents by (dx, dy) pixels.
        /// </summary>
        /// <param name="dx">Shift amount along the horizontal axis.</param>
        /// <param name="dy">Shift amount along the vertical axis.</param>
        // Token: 0x06000159 RID: 345 RVA: 0x00007C28 File Offset: 0x00005E28
        public void HShiftWindowContents(double dx, double dy)
        {
            int num;
            int num2;
            int num3;
            int num4;
            this._hwindow.GetWindowExtents(out num, out num2, out num3, out num4);
            double num5;
            double num6;
            double num7;
            double num8;
            this.GetFloatPart(this._hwindow, out num5, out num6, out num7, out num8);
            double num9 = (num8 - num6 + 1.0) / (double)num3;
            double num10 = (num7 - num5 + 1.0) / (double)num4;
            try
            {
                double num11 = num5 + dy * num10;
                double num12 = num7 + dy * num10;
                double num13 = num6 + dx * num9;
                double num14 = num8 + dx * num9;
                this.HImagePart = new Rect(num13, num11, num14 - num13 + 1.0, num12 - num11 + 1.0);
            }
            catch (HalconException)
            {
                this.HImagePart = new Rect(num6, num5, num8 - num6 + 1.0, num7 - num5 + 1.0);
            }
        }

        // Token: 0x0600015A RID: 346 RVA: 0x00007D0C File Offset: 0x00005F0C
        private void HWPFWindow_MouseMove(object sender, MouseEventArgs e)
        {
            HSmartWindowControlWPF.HMouseEventArgsWPF e2 = null;
            try
            {
                if (this._delayed)
                {
                    return;
                }
                System.Windows.Point position = this.GetPosition(e);
                bool flag = false;
                if (this._left_button_down && this.InteractingWithDrawingObjs())
                {
                    double d;
                    double d2;
                    this.ConvertWindowsCoordinatesToHImage(position.Y, position.X, out d, out d2);
                    //flag = this._hwindow.SendMouseDragEvent(d, d2, this.MouseEventToInt(e))[0].S.Equals("true");
                    flag = this._hwindow.SendMouseDragEvent(d, d2, this.MouseEventToInt(e)).Equals("true");
                }
                if (this._left_button_down && !flag && this.HMoveContent)
                {
                    this.HShiftWindowContents(this._last_position.X - position.X, this._last_position.Y - position.Y);
                }
                this._last_position = position;
                e2 = this.ToHMouse((int)this._last_position.X, (int)this._last_position.Y, e, 0);
            }
            catch (HalconException he)
            {
                if (this.HErrorNotify != null)
                {
                    this.HErrorNotify(he);
                }
            }
            if (this.HMouseMove != null)
            {
                this.HMouseMove(this, e2);
            }
        }

        /// <summary>
        /// Converts mouse position relative to the canvas in DPI units, to
        /// physical pixels. Things to be aware of
        /// https://wpf.2000things.com/tag/getposition/.
        /// </summary>
        /// <param name="e">The mouse event.</param>
        /// <returns>The transformed point coordinates.</returns>
        // Token: 0x0600015B RID: 347 RVA: 0x00007E3C File Offset: 0x0000603C
        private System.Windows.Point GetPosition(MouseEventArgs e)
        {
            return e.GetPosition(this);
        }

        // Token: 0x0600015C RID: 348 RVA: 0x00007E48 File Offset: 0x00006048
        private void HWPFWindow_MouseDown(object sender, MouseButtonEventArgs e)
        {
            HSmartWindowControlWPF.HMouseEventArgsWPF e2 = null;
            try
            {
                if (this._delayed)
                {
                    return;
                }
                this._left_button_down = (e.LeftButton == MouseButtonState.Pressed);
                this._last_position = this.GetPosition(e);
                if (this.InteractingWithDrawingObjs())
                {
                    double d;
                    double d2;
                    this.ConvertWindowsCoordinatesToHImage(this._last_position.Y, this._last_position.X, out d, out d2);
                    this._hwindow.SendMouseDownEvent(d, d2, this.MouseButtonEventToInt(e));
                }
                e2 = this.ToHMouse((int)this._last_position.X, (int)this._last_position.Y, e, 0);
            }
            catch (HalconException he)
            {
                if (this.HErrorNotify != null)
                {
                    this.HErrorNotify(he);
                }
            }
            if (this.HMouseDown != null)
            {
                this.HMouseDown(this, e2);
            }
        }

        // Token: 0x0600015D RID: 349 RVA: 0x00007F28 File Offset: 0x00006128
        private Rect Part2Rect()
        {
            HTuple htuple;
            HTuple htuple2;
            HTuple t;
            HTuple t2;
            this._hwindow.GetPart(out htuple, out htuple2, out t, out t2);
            return new Rect(htuple2, htuple, t2 - htuple2 + 1, t - htuple + 1);
        }

        /// <summary>
        ///   Adapt ImagePart to show the full image. If HKeepAspectRatio is on,
        ///   the contents of the HALCON window are rescaled while keeping the aspect
        ///   ratio. Otherwise, the HALCON window contents are rescaled to fill up
        ///   the HSmartWindowControlWPF.
        /// </summary>
        // Token: 0x0600015E RID: 350 RVA: 0x00007F80 File Offset: 0x00006180
        public void SetFullImagePart(HImage reference = null)
        {
            if (base.ActualHeight == 0.0 || base.ActualWidth == 0.0)
            {
                return;
            }
            if (reference != null)
            {
                int num;
                int num2;
                reference.GetImageSize(out num, out num2);
                this.HImagePart = new Rect(0.0, 0.0, (double)(num - 1), (double)(num2 - 1));
                return;
            }
            if (this.HKeepAspectRatio)
            {
                this._hwindow.SetPart(0, 0, -2, -2);
                this.HImagePart = this.Part2Rect();
                return;
            }
            this._hwindow.SetPart(0, 0, -1, -1);
            this.HImagePart = this.Part2Rect();
        }

        // Token: 0x0600015F RID: 351 RVA: 0x00008024 File Offset: 0x00006224
        private void HWPFWindow_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            HSmartWindowControlWPF.HMouseEventArgsWPF e2 = null;
            try
            {
                bool flag = false;
                this._last_position = this.GetPosition(e);
                if (e.ChangedButton == MouseButton.Left && this.InteractingWithDrawingObjs())
                {
                    double d;
                    double d2;
                    this.ConvertWindowsCoordinatesToHImage(this._last_position.Y, this._last_position.X, out d, out d2);
                    //flag = this._hwindow.SendMouseDoubleClickEvent(d, d2, this.MouseButtonEventToInt(e))[0].S.Equals("true");
                    flag = this._hwindow.SendMouseDoubleClickEvent(d, d2, this.MouseButtonEventToInt(e)).Equals("true");
                }
                if (!flag && this.HDoubleClickToFitContent)
                {
                    this.SetFullImagePart(null);
                }
                e2 = this.ToHMouse((int)this._last_position.X, (int)this._last_position.Y, e, 0);
            }
            catch (HalconException he)
            {
                if (this.HErrorNotify != null)
                {
                    this.HErrorNotify(he);
                }
            }
            if (this.HMouseDoubleClick != null)
            {
                this.HMouseDoubleClick(this, e2);
            }
        }

        // Token: 0x06000160 RID: 352 RVA: 0x00008120 File Offset: 0x00006320
        private void HWPFWindow_MouseUp(object sender, MouseButtonEventArgs e)
        {
            HSmartWindowControlWPF.HMouseEventArgsWPF e2 = null;
            try
            {
                this._left_button_down = false;
                this._last_position = this.GetPosition(e);
                if (this.InteractingWithDrawingObjs())
                {
                    double d;
                    double d2;
                    this.ConvertWindowsCoordinatesToHImage(this._last_position.Y, this._last_position.X, out d, out d2);
                    this._hwindow.SendMouseUpEvent(d, d2, this.MouseButtonEventToInt(e));
                }
                e2 = this.ToHMouse((int)this._last_position.X, (int)this._last_position.Y, e, 0);
            }
            catch (HalconException he)
            {
                if (this.HErrorNotify != null)
                {
                    this.HErrorNotify(he);
                }
            }
            if (this.HMouseUp != null)
            {
                this.HMouseUp(this, e2);
            }
        }

        // Token: 0x06000161 RID: 353 RVA: 0x000081EC File Offset: 0x000063EC
        private bool calculate_part(HTuple hv_WindowHandle, HTuple hv_WindowWidth, HTuple hv_WindowHeight)
        {
            HTuple htuple = null;
            HTuple htuple2 = null;
            HTuple htuple3 = null;
            HTuple htuple4 = null;
            HTuple htuple5 = null;
            HTuple htuple6 = null;
            HTuple t = null;
            HTuple t2 = null;
            HTuple homMat2D = null;
            HTuple homMat2D2 = null;
            HTuple htuple7 = null;
            HTuple htuple8 = null;
            bool result = true;
            HOperatorSet.GetPart(hv_WindowHandle, out htuple, out htuple2, out htuple3, out htuple4);
            try
            {
                HTuple t3 = htuple4 - htuple2 + 1;
                HTuple htuple9 = htuple3 - htuple + 1;
                   //t3 / htuple9.TupleReal();
                HOperatorSet.GetWindowExtents(hv_WindowHandle, out htuple5, out htuple6, out t, out t2);
                HTuple sx = t / hv_WindowWidth.TupleReal();
                HTuple sy = t2 / hv_WindowHeight.TupleReal();
                HTuple htuple10 = new HTuple();
                htuple10 = htuple10.TupleConcat((htuple + htuple3) * 0.5);
                htuple10 = htuple10.TupleConcat((htuple2 + htuple4) * 0.5);
                HOperatorSet.HomMat2dIdentity(out homMat2D);
                HOperatorSet.HomMat2dScale(homMat2D, sx, sy, htuple10.TupleSelect(1), htuple10.TupleSelect(0), out homMat2D2);
                HOperatorSet.AffineTransPoint2d(homMat2D2, htuple2.TupleConcat(htuple4), htuple.TupleConcat(htuple3), out htuple7, out htuple8);
                this.HImagePart = new Rect(htuple7.TupleSelect(0), htuple8.TupleSelect(0), htuple7.TupleSelect(1) - htuple7.TupleSelect(0) + 1, htuple8.TupleSelect(1) - htuple8.TupleSelect(0) + 1);
            }
            catch (HalconException)
            {
                this.HImagePart = new Rect(htuple2, htuple, htuple4 - htuple2 + 1, htuple3 - htuple + 1);
                result = false;
            }
            return result;
        }

        // Token: 0x06000162 RID: 354 RVA: 0x000083FC File Offset: 0x000065FC
        private void HWPFWindow_MouseLeave(object sender, MouseEventArgs e)
        {
            this._left_button_down = false;
        }

        // Token: 0x1400001C RID: 28
        // (add) Token: 0x06000163 RID: 355 RVA: 0x00008408 File Offset: 0x00006608
        // (remove) Token: 0x06000164 RID: 356 RVA: 0x00008440 File Offset: 0x00006640
        public event PropertyChangedEventHandler PropertyChanged;

        // Token: 0x06000165 RID: 357 RVA: 0x00008475 File Offset: 0x00006675
        protected internal void OnPropertyChanged(string propertyname)
        {
            if (this.PropertyChanged != null)
            {
                this.PropertyChanged(this, new PropertyChangedEventArgs(propertyname));
            }
        }

        /// <summary>
        /// If true, the content of the HSmartWindowControlWPF is moved when the mouse pointer is dragged.
        /// </summary>
        // Token: 0x04000083 RID: 131
        public static readonly DependencyProperty HMoveContentProperty = DependencyProperty.Register("HMoveContent", typeof(bool), typeof(HSmartWindowControlWPF), new PropertyMetadata(true));

        /// <summary>
        /// Controls the behavior of the mouse wheel.
        /// </summary>
        // Token: 0x04000084 RID: 132
        public static readonly DependencyProperty HZoomContentProperty = DependencyProperty.Register("HZoomContent", typeof(HSmartWindowControlWPF.ZoomContent), typeof(HSmartWindowControlWPF), new PropertyMetadata(HSmartWindowControlWPF.ZoomContent.WheelForwardZoomsIn));

        /// <summary>
        /// Define of min max range valid for HZoomFactor
        /// </summary>
        // Token: 0x04000085 RID: 133
        private const int HZoomFactorMin = 1;

        // Token: 0x04000086 RID: 134
        private const int HZoomFactorMax = 100;

        /// <summary>
        /// Controls the behavior of zoom factor controlled by the mouse wheel
        /// </summary>
        // Token: 0x04000087 RID: 135
        public static DependencyProperty HZoomFactorProperty = DependencyProperty.Register("HZoomFactor", typeof(double), typeof(HSmartWindowControlWPF), new PropertyMetadata(Math.Round(Math.Sqrt(2.0), 2)), new ValidateValueCallback(HSmartWindowControlWPF.HZoomFactorValidation));

        // Token: 0x04000088 RID: 136
        public static readonly DependencyProperty HColorProperty = DependencyProperty.Register("HColor", typeof(string), typeof(HSmartWindowControlWPF), new PropertyMetadata(null, new PropertyChangedCallback(HSmartWindowControlWPF.OnDrawingPropertyChanged)));

        // Token: 0x04000089 RID: 137
        public static readonly DependencyProperty HColoredProperty = DependencyProperty.Register("HColored", typeof(int?), typeof(HSmartWindowControlWPF), new PropertyMetadata(null, new PropertyChangedCallback(HSmartWindowControlWPF.OnDrawingPropertyChanged)));

        // Token: 0x0400008A RID: 138
        public static readonly DependencyProperty HLineStyleProperty = DependencyProperty.Register("HLineStyle", typeof(HLineStyleWPF), typeof(HSmartWindowControlWPF), new PropertyMetadata(null, new PropertyChangedCallback(HSmartWindowControlWPF.OnDrawingPropertyChanged)));

        // Token: 0x0400008B RID: 139
        public static readonly DependencyProperty HLineWidthProperty = DependencyProperty.Register("HLineWidth", typeof(double?), typeof(HSmartWindowControlWPF), new PropertyMetadata(null, new PropertyChangedCallback(HSmartWindowControlWPF.OnDrawingPropertyChanged)));

        // Token: 0x0400008C RID: 140
        public static readonly DependencyProperty HDrawProperty = DependencyProperty.Register("HDraw", typeof(string), typeof(HSmartWindowControlWPF), new PropertyMetadata(null, new PropertyChangedCallback(HSmartWindowControlWPF.OnDrawingPropertyChanged)));

        // Token: 0x0400008D RID: 141
        public static readonly DependencyProperty HFontProperty = DependencyProperty.Register("HFont", typeof(string), typeof(HSmartWindowControlWPF), new PropertyMetadata(null, new PropertyChangedCallback(HSmartWindowControlWPF.OnDrawingPropertyChanged)));

        // Token: 0x0400008E RID: 142
        public static readonly DependencyProperty HDisableAutoResizeProperty = DependencyProperty.Register("HDisableAutoResize", typeof(bool), typeof(HSmartWindowControlWPF), new PropertyMetadata(false));

        /// <summary>
        /// When assigned to a HObject, it causes the window to be cleared, and the new
        /// object will be displayed. In case it is an image, the aspect ratio will be updated,
        /// so that the new image is properly displayed.
        /// If null, the contents of the HSmartWindowControlWPF are cleared.
        /// </summary>
        // Token: 0x0400008F RID: 143
        public static DependencyProperty HDisplayCurrentObjectProperty = DependencyProperty.Register("HDisplayCurrentObject", typeof(HObject), typeof(HSmartWindowControlWPF), new FrameworkPropertyMetadata(new PropertyChangedCallback(HSmartWindowControlWPF.OnDisplayObjectChanged)));

        /// <summary>
        /// Modifier key to interact with drawing objects. If a modifier key is selected,
        /// the user can only interact with drawing objects while keeping the modifier key pressed.
        /// This is especially useful when interacting with XLD drawing objects.
        /// </summary>
        // Token: 0x04000090 RID: 144
        public static readonly DependencyProperty HDrawingObjectsModifierProperty = DependencyProperty.Register("HDrawingObjectsModifier", typeof(HSmartWindowControlWPF.DrawingObjectsModifier), typeof(HSmartWindowControlWPF), new PropertyMetadata(HSmartWindowControlWPF.DrawingObjectsModifier.None));

        /// <summary>
        /// If true, the contents of the HALCON window are displayed keeping the aspect ratio.
        /// </summary>
        // Token: 0x04000091 RID: 145
        public static readonly DependencyProperty HKeepAspectRatioProperty = DependencyProperty.Register("HKeepAspectRatio", typeof(bool), typeof(HSmartWindowControlWPF), new PropertyMetadata(true));

        /// <summary>
        /// If true, double clicking resizes the content of the HSmartWindowControlWPF to fit the size of the control.
        /// </summary>
        // Token: 0x04000092 RID: 146
        public static readonly DependencyProperty HDoubleClickToFitContentProperty = DependencyProperty.Register("HDoubleClickToFitContent", typeof(bool), typeof(HSmartWindowControlWPF), new PropertyMetadata(true));

        /// <summary>
        /// Image part of the corresponding HALCON window.
        /// </summary>
        // Token: 0x04000093 RID: 147
        public static readonly DependencyProperty HImagePartProperty = DependencyProperty.Register("HImagePart", typeof(Rect), typeof(HSmartWindowControlWPF), new PropertyMetadata(new Rect(0.0, 0.0, 640.0, 480.0), new PropertyChangedCallback(HSmartWindowControlWPF.OnHImagePartChanged)));

        // Token: 0x04000094 RID: 148
        public static readonly DependencyProperty WindowSizeProperty = DependencyProperty.Register("WindowSize", typeof(System.Windows.Size), typeof(HSmartWindowControlWPF), new PropertyMetadata(new System.Windows.Size(320.0, 200.0)));

        // Token: 0x0400009B RID: 155
        private bool _left_button_down;

        /// <summary>
        /// Pixel coordinates of mouse pointer last position.
        /// </summary>
        // Token: 0x0400009C RID: 156
        private System.Windows.Point _last_position;

        // Token: 0x0400009D RID: 157
        private HWindow _hwindow;

        // Token: 0x0400009E RID: 158
        private Viewbox _window_frame;

        // Token: 0x0400009F RID: 159
        private double _dpiX;

        // Token: 0x040000A0 RID: 160
        private double _dpiY;

        // Token: 0x040000A1 RID: 161
        private HTuple _dump_params;

        /// <summary>
        /// We need to wait until the WPF element has been rendered, so that
        /// we can draw on it.
        /// </summary>
        // Token: 0x040000A2 RID: 162
        private bool _delayed;

        // Token: 0x040000A3 RID: 163
        private System.Drawing.Size _prevsize;

        // Token: 0x040000A4 RID: 164
        private HObject _dumpimg;

        // Token: 0x040000A5 RID: 165
        private WriteableBitmap _wbitmap;

        /// <summary>
        /// Provides data for the HMouse* events.
        /// </summary>
        // Token: 0x020000A5 RID: 165
        public class HMouseEventArgsWPF : EventArgs
        {
            // Token: 0x06002035 RID: 8245 RVA: 0x000BB4C0 File Offset: 0x000B96C0
            internal HMouseEventArgsWPF(double x, double y, double row, double column, int delta, MouseButton? button)
            {
                this.x = x;
                this.y = y;
                this.row = row;
                this.column = column;
                this.delta = delta;
                this.button = button;
            }

            /// <summary>Gets the window x coordinate of the mouse event.</summary>
            // Token: 0x170000A7 RID: 167
            // (get) Token: 0x06002036 RID: 8246 RVA: 0x000BB4F5 File Offset: 0x000B96F5
            public double X
            {
                get
                {
                    return this.x;
                }
            }

            /// <summary>Gets the window y coordinate of the mouse event.</summary>
            // Token: 0x170000A8 RID: 168
            // (get) Token: 0x06002037 RID: 8247 RVA: 0x000BB4FD File Offset: 0x000B96FD
            public double Y
            {
                get
                {
                    return this.y;
                }
            }

            /// <summary>Gets the row image coordinate of the mouse event.</summary>
            // Token: 0x170000A9 RID: 169
            // (get) Token: 0x06002038 RID: 8248 RVA: 0x000BB505 File Offset: 0x000B9705
            public double Row
            {
                get
                {
                    return this.row;
                }
            }

            /// <summary>Gets the column image coordinate of the mouse
            /// event.
            /// </summary>
            // Token: 0x170000AA RID: 170
            // (get) Token: 0x06002039 RID: 8249 RVA: 0x000BB50D File Offset: 0x000B970D
            public double Column
            {
                get
                {
                    return this.column;
                }
            }

            /// <summary>Gets the increment for the mouse wheel change.</summary>
            // Token: 0x170000AB RID: 171
            // (get) Token: 0x0600203A RID: 8250 RVA: 0x000BB515 File Offset: 0x000B9715
            public int Delta
            {
                get
                {
                    return this.delta;
                }
            }

            /// <summary>Gets which mouse button was pressed.</summary>
            // Token: 0x170000AC RID: 172
            // (get) Token: 0x0600203B RID: 8251 RVA: 0x000BB51D File Offset: 0x000B971D
            public MouseButton? Button
            {
                get
                {
                    return this.button;
                }
            }

            // Token: 0x04001199 RID: 4505
            private readonly double x;

            // Token: 0x0400119A RID: 4506
            private readonly double y;

            // Token: 0x0400119B RID: 4507
            private readonly double row;

            // Token: 0x0400119C RID: 4508
            private readonly double column;

            // Token: 0x0400119D RID: 4509
            private readonly int delta;

            // Token: 0x0400119E RID: 4510
            private readonly MouseButton? button;
        }

        /// <summary>
        /// Mouse wheel behavior
        /// </summary>
        // Token: 0x020000A6 RID: 166
        public enum ZoomContent
        {
            /// <summary>
            /// No effect on the contents
            /// </summary>
            // Token: 0x040011A0 RID: 4512
            Off,
            /// <summary>
            /// Moving the mouse wheel forward zooms in on the contents
            /// </summary>
            // Token: 0x040011A1 RID: 4513
            WheelForwardZoomsIn,
            /// <summary>
            /// Moving the mouse wheel backward zooms in on the contents
            /// </summary>
            // Token: 0x040011A2 RID: 4514
            WheelBackwardZoomsIn
        }

        /// <summary>
        /// Modifier to manipulate drawing objects
        /// </summary>
        // Token: 0x020000A7 RID: 167
        public enum DrawingObjectsModifier
        {
            /// <summary>
            /// Manipulate drawing objects without a modifier
            /// </summary>
            // Token: 0x040011A4 RID: 4516
            None,
            /// <summary>
            /// Shift key must be pressed to modify drawing objects
            /// </summary>
            // Token: 0x040011A5 RID: 4517
            Shift,
            /// <summary>
            /// Ctrl key must be pressed to modify drawing objects
            /// </summary>
            // Token: 0x040011A6 RID: 4518
            Ctrl,
            /// <summary>
            /// Alt key must be pressed to modify drawing objects
            /// </summary>
            // Token: 0x040011A7 RID: 4519
            Alt
        }

        /// <summary>
        /// Represents the method that will handle the HMouse* events
        /// of HWindowControlWPF
        /// </summary>
        // Token: 0x020000A8 RID: 168
        // (Invoke) Token: 0x0600203D RID: 8253
        public delegate void HMouseEventHandlerWPF(object sender, HSmartWindowControlWPF.HMouseEventArgsWPF e);

        /// <summary>
        /// In some situations (like a missing license in runtime), it can be the case that
        /// internal exceptions are thrown, and the user has no way of capturing them.
        /// This callback allows the user to react to such runtime errors.
        /// </summary>
        /// <param name="he"></param>
        // Token: 0x020000A9 RID: 169
        // (Invoke) Token: 0x06002041 RID: 8257
        public delegate void HErrorHandler(HalconException he);
    }
}
